package com.bit.catmoney;

import game.sb.PrefActivity;

import java.util.Random;

import com.bit.catmoney.R;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ToggleButton;

public class MainActivity extends Activity implements OnClickListener {

	CMusic myMusic;
	Random random = new Random();
	int[] arrbgm = { R.raw.snowman_bgm, R.raw.fun_bgm, };

	// private static MediaPlayer mPlayer;
	ToggleButton toggleButton1 = null;
	ToggleButton toggleButton2 = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_main);

		CFxSound.setIsPlay(true);

		myMusic = CMusic.getInstance();
		myMusic.loopStart(MainActivity.this, arrbgm[random.nextInt(2)]);

		// MediaPlayer mPlayer = MediaPlayer.create(this, R.raw.coin);

		myMusic = CMusic.getInstance();

		((Button) this.findViewById(R.id.ready_btn)).setOnClickListener(this);
		((Button) findViewById(R.id.explain_btn)).setOnClickListener(this);
		((Button) findViewById(R.id.rank_btn)).setOnClickListener(this);
		((Button) findViewById(R.id.opt_btn)).setOnClickListener(this);

		SharedPreferences prefs = getSharedPreferences("PrefName", MODE_PRIVATE);
		String txtid = prefs.getString(PrefActivity.KEY_MY_PREFERENCE, "");

		if (txtid == "") {
			Intent intent1 = new Intent(MainActivity.this, PrefActivity.class);
			startActivity(intent1);
		} else {
			TextView IDText = (TextView) findViewById(R.id.IDText);
			IDText.setText(txtid);
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.ready_btn:
			Intent intent = new Intent(MainActivity.this, ReadyActivity.class);
			// intent.putExtra("sb_bgm", );
			startActivity(intent);
			break;
		case R.id.explain_btn:
			Intent intent1 = new Intent(MainActivity.this,
					ExplainActivity.class);
			startActivity(intent1);
			break;
		case R.id.rank_btn:
			Intent intent3 = new Intent(MainActivity.this, RankActivity.class);
			startActivity(intent3);
			break;
		case R.id.opt_btn:

			Intent intent2 = new Intent(MainActivity.this, OptActivity.class);
			startActivity(intent2);
			break;
		default:
			break;
		}
	}


	public void onBackPressed() {
		android.os.Process.killProcess(android.os.Process.myPid());
		System.exit(0);
	}
	// @Override
	//
	// protected void onUserLeaveHint() {
	//
	// super.onUserLeaveHint();
	// android.os.Process.killProcess(android.os.Process.myPid());
	// System.exit(0);
	// }

}